#ifndef _IStorageSerializer_h_
#define _IStorageSerializer_h_

#include "StandardSerializer.h"
#include "Serializable.h"
#include "Persistor\Persistor.h"
#include "RecordSerializer.h"
#include <string>
#include <map>


using namespace common;

//a serialization implementation using
//structured storage (if you got one
//and it's COM-independent, he-he :)

namespace persist
{
//uncomment when ready------------------
//class IStorage; // a structured storage (standard notation)
//class IStream;  // a stream within structured storage
//--------------------------------------

class IStorageSerializer : public StandardSerializer
{
//uncomment when ready------------------	
//	IStorage* storage;
//	IStream* stream;                                                         
//--------------------------------------

public:
//uncomment when ready------------------
/*
	class StreamPush
    {
        IStream*& stream;
        IStream*	saved;
    public:
        StreamPush(IStream& s) : stream(s) {saved = s;}
        ~StreamPush() {stream = saved;}
    };
*/
//--------------------------------------

//uncomment when ready------------------
/*
protected:

//object allocation table
	//object name, address
    typedef std::map<std::string, ulong>    Item;
	//class id, map of objects
    typedef std::map<Identifier, Item>      Table;
    Table                   table;
    ulong                   address;
*/
//--------------------------------------
protected:
	
	virtual void serialize(void* data, size_t size);

//open or create a stream within structured storage
//uncomment when ready------------------
//	virtual void openStream(Persistor::Mode m, const std::string& fname,IStream** pstream);
//--------------------------------------

//construct or flush object's data from / to the storage
	virtual void fill(Persistent* _persistent);
//
	virtual void allocate(Persistent* _persistent);
	virtual void deallocate(Persistent* _persistent);

	//allocate a chunk of storage by identifier and return the given name
	virtual std::string allocate(const Identifier& _id);
	virtual void deallocate(const Identifier& _id);

//uncomment when ready------------------
//    IStorageSerializer(IStorage* _storage, IStream* _stream,
//					   const std::string& _name, Persistor::Mode m);
//--------------------------------------
public:
	IStorageSerializer();
	IStorageSerializer(const std::string& _name);
	IStorageSerializer(const std::string& _name, Persistor::Mode m = READ);
	virtual ~IStorageSerializer();

	virtual bool open(const std::string& fname, Persistor::Mode m = READ);
	virtual void close();
	virtual void clear();
	virtual bool isOpen();

//	virtual void persist(Persistent*& _persistent);
};
 	
} //namespace

#endif